#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author:Richard_Kong
"""
本例中使用正确的信息来登陆系统，并返回token值
步骤：
1、导包
2、创建类
3、定义前后置方法
4、创建测试用例函数
测试3
"""
import unittest
import requests
from config import config
from api.LogInAPI import LogInAPI
from tools.HTMLTestRunner import HTMLTestRunner
from common.common_assert import common_assert

class Test_Login(unittest.TestCase):
    def setUp(self) -> None:
        self.logapi = LogInAPI()
        self.session = requests.Session()
        pass

    def tearDown(self) -> None:
        if self.session:
            self.session.close()

    def test01_login(self):
        response = self.logapi.login(self.session, config.login_sucess_data)
        common_assert(self,response,True,10000,"操作成功！",200)
        # self.assertEqual(200,response.status_code)
        # self.assertEqual(True, response.json().get('success'))
        # self.assertEqual(10000, response.json().get('code'))
        # self.assertEqual('操作成功！', response.json().get('message'))
        config.login_token_data = response.json().get('data')
        config.Authorization = config.Authorization.format(config.login_token_data)    # 将token值和bear组合
        print(config.login_token_data,':',type(config.login_token_data))
        print(config.Authorization)


if __name__ == '__main__':
    test_suite = unittest.TestSuite()
    test_suite.addTest(Test_Login)
    report_file = '.report02.html'
    with open(file=report_file,mode='wb') as f:
        html_runner = HTMLTestRunner(stream=f,title = 'report2')
        html_runner.run(test_suite)